package com.lagou.entity;

import java.io.Serializable;
import java.util.List;

public class Student implements Serializable {
    private int id;
    private String stuId;
    private String name;
    private String sex;
    private String birthday;

    public Student() {
    }

    public Student(int id, String stuId, String name, String sex, String birthday) {
        this.id = id;
        this.stuId = stuId;
        this.name = name;
        this.sex = sex;
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", stuId='" + stuId + '\'' +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", birthday='" + birthday + '\'' +
                '}';
    }

//    public static String toJsonString(Student stu) {
//        return "{" +
//                "\"id\":" + stu.id +
//                ", \"stuId\":" + "\"" + stu.stuId + "\"" +
//                ", \"name\":" + "\"" + stu.name + "\"" +
//                ", \"sex\":" + "\"" + stu.sex + "\"" +
//                ", \"birthday\":" + "\"" + stu.birthday + "\"" +
//                '}';
//    }

    public String toJsonString() {
        return "{" +
                "\"id\":" + id +
                ", \"stuId\":" + "\"" + stuId + "\"" +
                ", \"name\":" + "\"" + name + "\"" +
                ", \"sex\":" + "\"" + sex + "\"" +
                ", \"birthday\":" + "\"" + birthday + "\"" +
                '}';
    }

    public static String toJsonString(List<Student> studentList) {
        StringBuilder json = new StringBuilder();
        json.append("[");
        for (int i = 0; i < studentList.size(); i++) {
            json.append(studentList.get(i).toJsonString());
            if (i < studentList.size() - 1) json.append(",");
        }
        json.append("]");
        return json.toString();
    }

//    public static void toJson(List<Student> students) {
//        StringBuilder json= new StringBuilder();
//        for (int i = 0; i < students.size(); i++) {
//            json.append("{");
//            Student student = students.get(i);
//            Object[] values = student.toarry();
//            for (int j = 0; j < keys.length; j++) {
//                json.append("\"" + keys[j] + "\":\"" + values[j] + "\"");
//                if (j < keys.length - 1) json.append(",");
//            }
//            json.append("}");
//            if (i < students.size() - 1) json.append(",");
//        }
//        json.append("]");
//    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getStuId() {
        return stuId;
    }

    public void setStuId(String stuId) {
        this.stuId = stuId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }
}
